package com.atguigu.product.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author polaris
 * @date 2021/1/19 1:17 下午
 */
@Configuration
public class MyThreadConfig {
  @Bean
  public ThreadPoolExecutor threadPoolExecutor(ThreadPoolConfigProperties pool) {
    return new ThreadPoolExecutor(
      pool.getCorePoolSize(),
      pool.getMaxPoolSize(),
      pool.getKeepAliveTime(),
      TimeUnit.SECONDS,
      new LinkedBlockingDeque<>(10000),
      new ThreadPoolExecutor.AbortPolicy()
    );
  }
}
